export const casLogin = (ticket) => {
    return new Promise((resolve, reject) => {
        global.Api.login({ ticket })
            .then(data => {
                if (data.status === "redirect") {
                    const url = window.location.href;
                    const pos = url.indexOf('redirect=');
                    if (pos > 0) {
                        setCASRedirect(url.substr(pos + 'redirect='.length));
                    } else {
                        setCASRedirect('/');
                    }
                    resolve({ status: "redirect", login_url: data.login_url });
                } else if (data.status === "login") {
                    setToken(data.token);
                    resolve({ status: "login" });
                } else {
                    console.log(data);
                    reject(new Error('登录API其他情况'));
                }
            })
            .catch(error => {
                reject(error);
            })
    })
};
